package com.gmw.yygh.hosp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gmw.yygh.hosp.mapper.HospitalSetMapper;
import com.gmw.yygh.hosp.service.HospitalSetService;
import com.gmw.yygh.model.hosp.HospitalSet;
import com.gmw.yygh.vo.hosp.HospitalSetQueryVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper,HospitalSet> implements HospitalSetService{

    @Override
    public Page<HospitalSet> selectPage(long current, long limit, HospitalSetQueryVo hospitalSetQueryVo) {
        //创建page对象，传递当前页和每页显示的条数
        Page<HospitalSet> page = new Page<>(current,limit);
        //构建条件
        QueryWrapper<HospitalSet> queryWrapper = new QueryWrapper<>();

        String hosname = hospitalSetQueryVo.getHosname();
        String hoscode = hospitalSetQueryVo.getHoscode();

        System.out.println("current: " + current);
        System.out.println("limit: " + limit);

        System.out.println("hosname: " + hosname);
        System.out.println("hoscode: " + hoscode);

        System.out.println("page: " + page);

        if(StringUtils.isEmpty(hosname)){
            queryWrapper.like("hosname",hospitalSetQueryVo.getHosname());
        }

        if(StringUtils.isEmpty(hoscode)){
            queryWrapper.eq("hoscode",hospitalSetQueryVo.getHoscode());
        }

        Page<HospitalSet> selectPage = this.baseMapper.selectPage(page, queryWrapper);
        return selectPage;
    }
}
